<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>DOM事件流</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    #div {
      width: 200px;
      height: 200px;
      background-color: pink;
    }
  </style>
</head>

<body>
  <div id="div">
    <button id="btn">点击按钮了吧</button>
  </div>
</body>
<script>
  "use strict"; {
    /* 
      DOM事件流包括三个阶段
        1.事件捕获阶段
        2.处于目标阶段
        3.事件冒泡阶段
      addEventListener最后一个参数(默认false)：false 为事件捕获  true 为事件冒泡
      e.stopPropagation() 能阻止事件冒泡或事件捕获
      e.stopImmediatePropagation() 能阻止事件冒泡或事件捕获，同时还能阻止了同一类型的事件触发
    */
    document.documentElement.addEventListener("click", () => {
      console.log("html")
    }, false) //冒泡
    document.body.addEventListener("click", () => {
      console.log("body")
    }, true) //捕获
    document.getElementById("div").addEventListener("click", () => {
      console.log("div")
    }, true)//捕获
    document.getElementById("btn").addEventListener("click", () => {
      console.log("btn")
    }, false) //冒泡

    // 输出 body  div  btn  html
  };
</script>

</html>